package cn.car.domains.vo;

import cn.car.domains.enums.StatusCode;
import lombok.Data;
import lombok.NoArgsConstructor;


@Data
@NoArgsConstructor
public class Result<T> {
    private String code;
    private String message;
    private T data;


    public Result(StatusCode statusCode) {
        this.code = statusCode.getCode();
        this.message = statusCode.getMessage();
    }

    public Result(String code, String message) {
        this.code = code;
        this.message = message;
    }


    public static <T> Result<T> success(String msg) {
        final Result<T> result = new Result<>(StatusCode.SUCCESS);
        result.setMessage(msg);
        return result;
    }

    public static <T> Result<T> success(T data) {
        final Result<T> result = new Result<>(StatusCode.SUCCESS);
        result.setData(data);
        return result;
    }

    public static Result<Void> success() {
        return new Result<>(StatusCode.SUCCESS);
    }

    public static <T> Result<T> error(String code, String message) {
        Result<T> result = new Result<>();
        result.setCode(code);
        result.setMessage(message);
        return result;
    }

}

